<template>
<div>
  <el-dialog
    :title="title"
    :close-on-click-modal="false"
     v-dialogDrag
    :visible.sync="visible">
    <el-form :model="inputForm" size="small" ref="inputForm" v-loading="loading" :class="method==='view'?'readonly':''"  :disabled="method==='view'"
             label-width="120px">
      <el-row  :gutter="15">
        <el-col :span="12">
            <el-form-item label="评价人" prop="evaluateUser.id"
                :rules="[
                  {required: true, message:'评价人不能为空', trigger:'blur'}
                 ]">
          <GridSelect
            title="选择评价人"
            labelName = 'userName'
            labelValue = 'id'
            :value = "inputForm.evaluateUser.id"
            :limit="1"
            @getValue='(value) => {inputForm.evaluateUser.id=value}'
            :columns="[
            {
              prop: 'id',
              label: '主键'
            },
            {
              prop: 'userName',
              label: '用户名'
            }
            ]"
            :searchs="[
            {
              prop: 'id',
              label: '主键'
            },
            {
              prop: 'userName',
              label: '用户名'
            }
            ]"
            dataListUrl="/lhyg/lgy/fuuserinformation/fuUserInformation/list"
            entityBeanName="userInformation"
            queryEntityUrl="/lhyg/lgy/fuuserinformation/fuUserInformation/queryById">
          </GridSelect>
           </el-form-item>
        </el-col>
        <el-col :span="12">
            <el-form-item label="评价时间" prop="evaluateTime"
                :rules="[
                  {required: true, message:'评价时间不能为空', trigger:'blur'}
                 ]">
                <el-date-picker
                      style="width: 100%;"
                      v-model="inputForm.evaluateTime"
                      type="datetime"
                      value-format="yyyy-MM-dd HH:mm:ss"
                      placeholder="选择日期时间">
                    </el-date-picker>
           </el-form-item>
        </el-col>
        <el-col :span="12">
            <el-form-item label="评价商品" prop="evaluateGoods.id"
                :rules="[
                  {required: true, message:'评价商品不能为空', trigger:'blur'}
                 ]">
          <GridSelect
            title="选择评价商品"
            labelName = 'goodsTitle'
            labelValue = 'id'
            :value = "inputForm.evaluateGoods.id"
            :limit="1"
            @getValue='(value) => {inputForm.evaluateGoods.id=value}'
            :columns="[
            {
              prop: 'id',
              label: '主键'
            },
            {
              prop: 'goodsTitle',
              label: '标题'
            }
            ]"
            :searchs="[
            {
              prop: 'id',
              label: '主键'
            },
            {
              prop: 'goodsTitle',
              label: '标题'
            }
            ]"
            dataListUrl="/lhyg/lgy/goodsdetails/goodsDetails/list"
            entityBeanName="goodsDetails"
            queryEntityUrl="/lhyg/lgy/goodsdetails/goodsDetails/queryById">
          </GridSelect>
           </el-form-item>
        </el-col>
        <el-col :span="12">
            <el-form-item label="评价内容" prop="evaluateContent"
                :rules="[
                  {required: true, message:'评价内容不能为空', trigger:'blur'}
                 ]">
          <el-input type="textarea" v-model="inputForm.evaluateContent" placeholder="请填写评价内容"     ></el-input>
           </el-form-item>
        </el-col>
        <el-col :span="12">
            <el-form-item label="评价图组" prop="evaluatePicture"
                :rules="[
                  {required: true, message:'评价图组不能为空', trigger:'blur'}
                 ]">
              <el-input v-model="inputForm.evaluatePicture" placeholder="请填写评价图组"     ></el-input>
           </el-form-item>
        </el-col>
        <el-col :span="12">
            <el-form-item label="评价等级" prop="evaluateGrade"
                :rules="[
                  {required: true, message:'评价等级不能为空', trigger:'blur'}
                 ]">
              <el-input v-model="inputForm.evaluateGrade" placeholder="请填写评价等级"     ></el-input>
           </el-form-item>
        </el-col>
        <el-col :span="12">
            <el-form-item label="父级编号" prop="parent.id"
                :rules="[
                 ]">
          <GridSelect
            title="选择父级编号"
            labelName = 'evaluateContent'
            labelValue = 'id'
            :value = "inputForm.parent.id"
            :limit="1"
            @getValue='(value) => {inputForm.parent.id=value}'
            :columns="[
            {
              prop: 'id',
              label: '主键'
            },
            {
              prop: 'evaluateContent',
              label: '评价内容'
            }
            ]"
            :searchs="[
            {
              prop: 'id',
              label: '主键'
            },
            {
              prop: 'evaluateContent',
              label: '评价内容'
            }
            ]"
            dataListUrl="/lhyg/lgy/goodsevaluate/goodsEvaluate/list"
            entityBeanName="goodsEvaluate"
            queryEntityUrl="/lhyg/lgy/goodsevaluate/goodsEvaluate/queryById">
          </GridSelect>
           </el-form-item>
        </el-col>
        <el-col :span="12">
            <el-form-item label="点赞量" prop="likesCount"
                :rules="[
                  {required: true, message:'点赞量不能为空', trigger:'blur'}
                 ]">
              <el-input v-model="inputForm.likesCount" placeholder="请填写点赞量"     ></el-input>
           </el-form-item>
        </el-col>
        <el-col :span="12">
            <el-form-item label="发布人id" prop="publisherId"
                :rules="[
                 ]">
              <el-input v-model="inputForm.publisherId" placeholder="请填写发布人id"     ></el-input>
           </el-form-item>
        </el-col>
        <el-col :span="12">
            <el-form-item label="企业或个人" prop="personalOrEnterprise"
                :rules="[
                 ]">
                <el-select v-model="inputForm.personalOrEnterprise" placeholder="请选择"  style="width: 100%;">
                          <el-option
                            v-for="item in $dictUtils.getDictList('personal_or_enterprise')"
                            :key="item.value"
                            :label="item.label"
                            :value="item.value">
                          </el-option>
                      </el-select>
           </el-form-item>
        </el-col>
        <el-col :span="12">
            <el-form-item label="评价关联订单" prop="evaluateOrder.id"
                :rules="[
                 ]">
          <GridSelect
            title="选择评价关联订单"
            labelName = 'orderNumber'
            labelValue = 'id'
            :value = "inputForm.evaluateOrder.id"
            :limit="1"
            @getValue='(value) => {inputForm.evaluateOrder.id=value}'
            :columns="[
            {
              prop: 'id',
              label: '主键'
            },
            {
              prop: 'orderNumber',
              label: '订单编号'
            }
            ]"
            :searchs="[
            {
              prop: 'id',
              label: '主键'
            },
            {
              prop: 'orderNumber',
              label: '订单编号'
            }
            ]"
            dataListUrl="/lhyg/lgy/lhyggoodsorder/lhygGoodsOrder/list"
            entityBeanName="lhygGoodsOrder"
            queryEntityUrl="/lhyg/lgy/lhyggoodsorder/lhygGoodsOrder/queryById">
          </GridSelect>
           </el-form-item>
        </el-col>
        <el-col :span="12">
            <el-form-item label="备注信息" prop="remarks"
                :rules="[
                 ]">
          <el-input type="textarea" v-model="inputForm.remarks" placeholder="请填写备注信息"     ></el-input>
           </el-form-item>
        </el-col>
        </el-row>
    </el-form>
    <span slot="footer" class="dialog-footer">
      <el-button size="small" @click="visible = false">关闭</el-button>
      <el-button size="small" type="primary" v-if="method != 'view'" @click="doSubmit()" v-noMoreClick>确定</el-button>
    </span>
  </el-dialog>
</div>
</template>

<script>
  import GridSelect from '@/components/gridSelect'
  export default {
    data () {
      return {
        title: '',
        method: '',
        visible: false,
        loading: false,
        inputForm: {
          id: '',
          evaluateUser: {
            id: ''
          },
          evaluateTime: '',
          evaluateGoods: {
            id: ''
          },
          evaluateContent: '',
          evaluatePicture: '',
          evaluateGrade: '',
          parent: {
            id: ''
          },
          likesCount: '',
          remarks: '',
          publisherId: '',
          personalOrEnterprise: '',
          evaluateOrder: {
            id: ''
          }
        }
      }
    },
    components: {
      GridSelect
    },
    methods: {
      init (method, id) {
        this.method = method
        this.inputForm.id = id
        if (method === 'add') {
          this.title = `新建商品评价`
        } else if (method === 'edit') {
          this.title = '修改商品评价'
        } else if (method === 'view') {
          this.title = '查看商品评价'
        }
        this.visible = true
        this.loading = false
        this.$nextTick(() => {
          this.$refs.inputForm.resetFields()
          if (method === 'edit' || method === 'view') { // 修改或者查看
            this.loading = true
            this.$http({
              url: `/lhyg/lgy/goodsevaluate/goodsEvaluate/queryById?id=${this.inputForm.id}`,
              method: 'get'
            }).then(({data}) => {
              this.inputForm = this.recover(this.inputForm, data.goodsEvaluate)
              this.loading = false
            })
          }
        })
      },
      // 表单提交
      doSubmit () {
        this.$refs['inputForm'].validate((valid) => {
          if (valid) {
            this.loading = true
            this.$http({
              url: `/lhyg/lgy/goodsevaluate/goodsEvaluate/save`,
              method: 'post',
              data: this.inputForm
            }).then(({data}) => {
              this.loading = false
              if (data && data.success) {
                this.visible = false
                this.$message.success(data.msg)
                this.$emit('refreshDataList')
              }
            })
          }
        })
      }
    }
  }
</script>